package cn.edu.imau.zy.system.controller;

import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.imau.zy.common.annotation.LoginUser;
import cn.edu.imau.zy.common.core.entity.system.SysUser;
import cn.edu.imau.zy.common.core.entity.teacher.TcTeacher;

import cn.edu.imau.zy.common.core.domain.R;
import cn.edu.imau.zy.common.core.controller.BaseController;
import cn.edu.imau.zy.system.service.ITcTeacherService;

import java.util.List;
import java.util.Map;

/**
 * 教师信息 提供者
 * 
 * @author wyz
 * @date 2020-06-23
 */
@RestController
@RequestMapping("teacher")
public class TcTeacherController extends BaseController
{
	
	@Autowired
	private ITcTeacherService tcTeacherService;
	
	/**
	 * 查询${tableComment}
	 */
	@GetMapping("get/{teacherId}")
	public TcTeacher get(@PathVariable("teacherId") Long teacherId)
	{
		return tcTeacherService.selectTcTeacherById(teacherId);
		
	}
	
	/**
	 * 查询教师信息列表-分页
	 */
	@GetMapping("list")
	public R list(TcTeacher tcTeacher)
	{
		startPage();
        return result(tcTeacherService.selectTcTeacherList(tcTeacher));
	}

    /**
     * 查询教师信息列表
     */
    @GetMapping("jlist")
    public List<TcTeacher> jList(TcTeacher tcTeacher)
    {

        return tcTeacherService.selectTcTeacherList(tcTeacher);
    }

    /**
     * 查询班主任信息列表-分页
     */
    @PostMapping("forClassesList")
    public R forClassesList(@RequestBody Map<String, Object> params) {
        startPage();
        return result(tcTeacherService.forClassesList(params));
    }
	
	
	/**
	 * 新增保存教师信息
	 */
	@PostMapping("save")
	public R addSave(@RequestBody TcTeacher tcTeacher,@LoginUser SysUser user)
	{
		tcTeacher.setTeacherId(IdUtil.getSnowflake(1,1).nextIdStr());
        tcTeacher.setCreateBy(user.getUserId().toString());
		return toAjax(tcTeacherService.insertTcTeacher(tcTeacher));
	}

	/**
	 * 修改保存教师信息
	 */
	@PostMapping("update")
	public R editSave(@RequestBody TcTeacher tcTeacher,@LoginUser SysUser user)
	{
        tcTeacher.setUpdateBy(user.getUserId().toString());
		return toAjax(tcTeacherService.updateTcTeacher(tcTeacher));
	}
	
	/**
	 * 删除${tableComment}
	 */
	@PostMapping("remove")
	public R remove(String ids)
	{		
		return toAjax(tcTeacherService.deleteTcTeacherByIds(ids));
	}
	
}
